﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    //using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.CommonMethodServiceRef;

    public class LotTemplate : BasePage
    {
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected CheckBox chkIsActive;
        protected CheckBox chkLotMandatory01;
        protected CheckBox chkLotMandatory02;
        protected CheckBox chkLotMandatory03;
        protected CheckBox chkLotMandatory04;
        protected CheckBox chkLotMandatory05;
        protected CheckBox chkLotMandatory06;
        protected CheckBox chkLotMandatory07;
        protected CheckBox chkLotMandatory08;
        protected CheckBox chkLotMandatory09;
        protected CheckBox chkLotMandatory10;
        protected CheckBox chkLotMandatory11;
        protected CheckBox chkLotMandatory12;
        protected CheckBox chkLotMandatory13;
        protected CheckBox chkLotRFVisible01;
        protected CheckBox chkLotRFVisible02;
        protected CheckBox chkLotRFVisible03;
        protected CheckBox chkLotRFVisible04;
        protected CheckBox chkLotRFVisible05;
        protected CheckBox chkLotRFVisible06;
        protected CheckBox chkLotRFVisible07;
        protected CheckBox chkLotRFVisible08;
        protected CheckBox chkLotRFVisible09;
        protected CheckBox chkLotRFVisible10;
        protected CheckBox chkLotRFVisible11;
        protected CheckBox chkLotRFVisible12;
        protected CheckBox chkLotRFVisible13;
        protected CheckBox chkLotVisible01;
        protected CheckBox chkLotVisible02;
        protected CheckBox chkLotVisible03;
        protected CheckBox chkLotVisible04;
        protected CheckBox chkLotVisible05;
        protected CheckBox chkLotVisible06;
        protected CheckBox chkLotVisible07;
        protected CheckBox chkLotVisible08;
        protected CheckBox chkLotVisible09;
        protected CheckBox chkLotVisible10;
        protected CheckBox chkLotVisible11;
        protected CheckBox chkLotVisible12;
        protected CheckBox chkLotVisible13;
        protected CheckBox chkSubLotRFVisible01;
        protected CheckBox chkSubLotRFVisible02;
        protected CheckBox chkSubLotRFVisible03;
        protected CheckBox chkSubLotRFVisible04;
        protected CheckBox chkSubLotRFVisible05;
        protected CheckBox chkSubLotRFVisible06;
        protected CheckBox chkSubLotRFVisible07;
        protected CheckBox chkSubLotRFVisible08;
        protected CheckBox chkSubLotRFVisible09;
        protected CheckBox chkSubLotRFVisible10;
        protected CheckBox chkSubLotRFVisible11;
        protected CheckBox chkSubLotRFVisible12;
        protected CheckBox chkSubLotRFVisible13;
        protected CheckBox chkSubLotVisible01;
        protected CheckBox chkSubLotVisible02;
        protected CheckBox chkSubLotVisible03;
        protected CheckBox chkSubLotVisible04;
        protected CheckBox chkSubLotVisible05;
        protected CheckBox chkSubLotVisible06;
        protected CheckBox chkSubLotVisible07;
        protected CheckBox chkSubLotVisible08;
        protected CheckBox chkSubLotVisible09;
        protected CheckBox chkSubLotVisible10;
        protected CheckBox chkSubLotVisible11;
        protected CheckBox chkSubLotVisible12;
        protected CheckBox chkSubLotVisible13;
        protected CheckBox chkSysCreated;
        protected DropDownList ddlLotType01;
        protected DropDownList ddlLotType02;
        protected DropDownList ddlLotType03;
        protected DropDownList ddlLotType04;
        protected DropDownList ddlLotType05;
        protected DropDownList ddlLotType06;
        protected DropDownList ddlLotType07;
        protected DropDownList ddlLotType08;
        protected DropDownList ddlLotType09;
        protected DropDownList ddlLotType10;
        protected DropDownList ddlLotValue01;
        protected DropDownList ddlLotValue02;
        protected DropDownList ddlLotValue03;
        protected DropDownList ddlLotValue04;
        protected DropDownList ddlLotValue05;
        protected DropDownList ddlLotValue06;
        protected DropDownList ddlLotValue07;
        protected DropDownList ddlLotValue08;
        protected DropDownList ddlLotValue09;
        protected DropDownList ddlLotValue10;
        protected HtmlForm F2081;
        protected HtmlInputHidden hdnFrom;
        protected Label lblDescription;
        protected Label lblDispalyName;
        protected Label lblExternal;
        protected Label lblLot01;
        protected Label lblLot02;
        protected Label lblLot03;
        protected Label lblLot04;
        protected Label lblLot05;
        protected Label lblLot06;
        protected Label lblLot07;
        protected Label lblLot08;
        protected Label lblLot09;
        protected Label lblLot10;
        protected Label lblLot11;
        protected Label lblLot12;
        protected Label lblLotTemplate;
        protected Label lblLotTemplateID;
        protected Label lblMandatory;
        protected Label lblMsg;
        protected Label lblRFVisible;
        protected Label lblSeqNo;
        protected Label lblType;
        protected Label lblValue;
        protected Label lblVisible;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        private List<SysCode4DDL> sysCodeLotAttrType;
        private List<string> sysCodeLotAttrValue;
        protected TextBox txtDescription;
        protected TextBox txtExpiryDate;
        protected TextBox txtExternal;
        protected TextBox txtLot01;
        protected TextBox txtLot02;
        protected TextBox txtLot03;
        protected TextBox txtLot04;
        protected TextBox txtLot05;
        protected TextBox txtLot06;
        protected TextBox txtLot07;
        protected TextBox txtLot08;
        protected TextBox txtLot09;
        protected TextBox txtLot10;
        protected TextBox txtLotTemplateID;
        protected TextBox txtLotValue01;
        protected TextBox txtLotValue02;
        protected TextBox txtLotValue03;
        protected TextBox txtLotValue04;
        protected TextBox txtLotValue05;
        protected TextBox txtLotValue06;
        protected TextBox txtLotValue07;
        protected TextBox txtLotValue08;
        protected TextBox txtLotValue09;
        protected TextBox txtLotValue10;
        protected TextBox txtProduct;
        protected TextBox txtSeqNo1;
        protected TextBox txtSeqNo10;
        protected TextBox txtSeqNo11;
        protected TextBox txtSeqNo12;
        protected TextBox txtSeqNo13;
        protected TextBox txtSeqNo2;
        protected TextBox txtSeqNo3;
        protected TextBox txtSeqNo4;
        protected TextBox txtSeqNo5;
        protected TextBox txtSeqNo6;
        protected TextBox txtSeqNo7;
        protected TextBox txtSeqNo8;
        protected TextBox txtSeqNo9;
        protected UpdatePanel up1;

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtLotTemplateID.Text = "";
            this.txtLotTemplateID.Enabled = true;
            this.chkSysCreated.Checked = false;
            base.DataEntityViewState = null;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.chkSysCreated.Checked)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C011");
            }
            else if (!string.IsNullOrEmpty(this.txtLotTemplateID.Text.Trim()))
            {
                try
                {
                    List<string> lotTemplateID = new List<string> {
                        this.txtLotTemplateID.Text.Trim()
                    };
                    this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Delete(lotTemplateID, "LOT_TEMPLATE") + base.GetGlobalMsgResource("C006");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                    base.DataEntityViewState = null;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("LotTemplateQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("LotTemplateList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtLotTemplateID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2081_001");
            }
            else if ((this.chkLotVisible01.Checked || this.chkLotMandatory01.Checked) && string.IsNullOrEmpty(this.txtLot01.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot01.Text, this.lblDispalyName.Text);
                this.txtLot01.Focus();
            }
            else if ((this.chkLotVisible02.Checked || this.chkLotMandatory02.Checked) && string.IsNullOrEmpty(this.txtLot02.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot02.Text, this.lblDispalyName.Text);
                this.txtLot02.Focus();
            }
            else if ((this.chkLotVisible03.Checked || this.chkLotMandatory03.Checked) && string.IsNullOrEmpty(this.txtLot03.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot03.Text, this.lblDispalyName.Text);
                this.txtLot03.Focus();
            }
            else if ((this.chkLotVisible04.Checked || this.chkLotMandatory04.Checked) && string.IsNullOrEmpty(this.txtLot04.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot04.Text, this.lblDispalyName.Text);
                this.txtLot04.Focus();
            }
            else if ((this.chkLotVisible05.Checked || this.chkLotMandatory05.Checked) && string.IsNullOrEmpty(this.txtLot05.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot05.Text, this.lblDispalyName.Text);
                this.txtLot05.Focus();
            }
            else if ((this.chkLotVisible06.Checked || this.chkLotMandatory06.Checked) && string.IsNullOrEmpty(this.txtLot06.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot06.Text, this.lblDispalyName.Text);
                this.txtLot06.Focus();
            }
            else if ((this.chkLotVisible07.Checked || this.chkLotMandatory07.Checked) && string.IsNullOrEmpty(this.txtLot07.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot07.Text, this.lblDispalyName.Text);
                this.txtLot07.Focus();
            }
            else if ((this.chkLotVisible08.Checked || this.chkLotMandatory08.Checked) && string.IsNullOrEmpty(this.txtLot08.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot08.Text, this.lblDispalyName.Text);
                this.txtLot08.Focus();
            }
            else if ((this.chkLotVisible09.Checked || this.chkLotMandatory09.Checked) && string.IsNullOrEmpty(this.txtLot09.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot09.Text, this.lblDispalyName.Text);
                this.txtLot09.Focus();
            }
            else if ((this.chkLotVisible10.Checked || this.chkLotMandatory10.Checked) && string.IsNullOrEmpty(this.txtLot10.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot10.Text, this.lblDispalyName.Text);
                this.txtLot10.Focus();
            }
            else if ((this.chkLotVisible11.Checked || this.chkLotMandatory11.Checked) && string.IsNullOrEmpty(this.txtProduct.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot11.Text, this.lblDispalyName.Text);
                this.txtProduct.Focus();
            }
            else if ((this.chkLotVisible12.Checked || this.chkLotMandatory12.Checked) && string.IsNullOrEmpty(this.txtExpiryDate.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblLot12.Text, this.lblDispalyName.Text);
                this.txtExpiryDate.Focus();
            }
            else if ((this.chkLotVisible13.Checked || this.chkLotMandatory13.Checked) && string.IsNullOrEmpty(this.txtExternal.Text.Trim()))
            {
                this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2081_002"), this.lblExternal.Text, this.lblDispalyName.Text);
                this.txtExternal.Focus();
            }
            else if (base.DataEntityViewState != null)
            {
                this.UpdateLotTemplateInfo();
            }
            else
            {
                this.InsertLotTemplateInfo();
            }
        }

        private LotTemplateInfo GetLotTemplateInfo4Form(LotTemplateInfo lotTemplateInfo)
        {
            int tempInt = 0;
            lotTemplateInfo.LotTemplateID = this.txtLotTemplateID.Text.Trim();
            lotTemplateInfo.Description = this.txtDescription.Text.Trim();
            lotTemplateInfo.SystemCreated = this.chkSysCreated.Checked ? "Y" : "N";
            lotTemplateInfo.IsActive = this.chkIsActive.Checked ? "Y" : "N";
            if (int.TryParse(this.txtSeqNo1.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr01Seqno = int.Parse(this.txtSeqNo1.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr01Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr01Label = this.txtLot01.Text.Trim();
            lotTemplateInfo.LotAttr01Visible = this.chkLotVisible01.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr01Visible = this.chkLotRFVisible01.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr01Mandatory = this.chkLotMandatory01.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr01Type = this.ddlLotType01.SelectedValue;
            lotTemplateInfo.LotAttr01Value = (this.ddlLotType01.SelectedValue == "OptionList") ? this.ddlLotValue01.SelectedValue : this.txtLotValue01.Text.Trim();
            if (int.TryParse(this.txtSeqNo2.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr02Seqno = int.Parse(this.txtSeqNo2.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr02Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr02Label = this.txtLot02.Text.Trim();
            lotTemplateInfo.LotAttr02Visible = this.chkLotVisible02.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr02Visible = this.chkLotRFVisible02.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr02Mandatory = this.chkLotMandatory02.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr02Type = this.ddlLotType02.SelectedValue;
            lotTemplateInfo.LotAttr02Value = (this.ddlLotType02.SelectedValue == "OptionList") ? this.ddlLotValue02.SelectedValue : this.txtLotValue02.Text.Trim();
            if (int.TryParse(this.txtSeqNo3.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr03Seqno = int.Parse(this.txtSeqNo3.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr03Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr03Label = this.txtLot03.Text.Trim();
            lotTemplateInfo.LotAttr03Visible = this.chkLotVisible03.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr03Visible = this.chkLotRFVisible03.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr03Mandatory = this.chkLotMandatory03.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr03Type = this.ddlLotType03.SelectedValue;
            lotTemplateInfo.LotAttr03Value = (this.ddlLotType03.SelectedValue == "OptionList") ? this.ddlLotValue03.SelectedValue : this.txtLotValue03.Text.Trim();
            if (int.TryParse(this.txtSeqNo4.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr04Seqno = int.Parse(this.txtSeqNo4.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr04Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr04Label = this.txtLot04.Text.Trim();
            lotTemplateInfo.LotAttr04Visible = this.chkLotVisible04.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr04Visible = this.chkLotRFVisible04.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr04Mandatory = this.chkLotMandatory04.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr04Type = this.ddlLotType04.SelectedValue;
            lotTemplateInfo.LotAttr04Value = (this.ddlLotType04.SelectedValue == "OptionList") ? this.ddlLotValue04.SelectedValue : this.txtLotValue04.Text.Trim();
            if (int.TryParse(this.txtSeqNo5.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr05Seqno = int.Parse(this.txtSeqNo5.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr05Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr05Label = this.txtLot05.Text.Trim();
            lotTemplateInfo.LotAttr05Visible = this.chkLotVisible05.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr05Visible = this.chkLotRFVisible05.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr05Mandatory = this.chkLotMandatory05.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr05Type = this.ddlLotType05.SelectedValue;
            lotTemplateInfo.LotAttr05Value = (this.ddlLotType05.SelectedValue == "OptionList") ? this.ddlLotValue05.SelectedValue : this.txtLotValue05.Text.Trim();
            if (int.TryParse(this.txtSeqNo6.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr06Seqno = int.Parse(this.txtSeqNo6.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr06Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr06Label = this.txtLot06.Text.Trim();
            lotTemplateInfo.LotAttr06Visible = this.chkLotVisible06.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr06Visible = this.chkLotRFVisible06.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr06Mandatory = this.chkLotMandatory06.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr06Type = this.ddlLotType06.SelectedValue;
            lotTemplateInfo.LotAttr06Value = (this.ddlLotType06.SelectedValue == "OptionList") ? this.ddlLotValue06.SelectedValue : this.txtLotValue06.Text.Trim();
            if (int.TryParse(this.txtSeqNo7.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr07Seqno = int.Parse(this.txtSeqNo7.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr07Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr07Label = this.txtLot07.Text.Trim();
            lotTemplateInfo.LotAttr07Visible = this.chkLotVisible07.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr07Visible = this.chkLotRFVisible07.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr07Mandatory = this.chkLotMandatory07.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr07Type = this.ddlLotType07.SelectedValue;
            lotTemplateInfo.LotAttr07Value = (this.ddlLotType07.SelectedValue == "OptionList") ? this.ddlLotValue07.SelectedValue : this.txtLotValue07.Text.Trim();
            if (int.TryParse(this.txtSeqNo8.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr08Seqno = int.Parse(this.txtSeqNo8.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr08Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr08Label = this.txtLot08.Text.Trim();
            lotTemplateInfo.LotAttr08Visible = this.chkLotVisible08.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr08Visible = this.chkLotRFVisible08.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr08Mandatory = this.chkLotMandatory08.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr08Type = this.ddlLotType08.SelectedValue;
            lotTemplateInfo.LotAttr08Value = (this.ddlLotType08.SelectedValue == "OptionList") ? this.ddlLotValue08.SelectedValue : this.txtLotValue08.Text.Trim();
            if (int.TryParse(this.txtSeqNo9.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr09Seqno = int.Parse(this.txtSeqNo9.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr09Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr09Label = this.txtLot09.Text.Trim();
            lotTemplateInfo.LotAttr09Visible = this.chkLotVisible09.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr09Visible = this.chkLotRFVisible09.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr09Mandatory = this.chkLotMandatory09.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr09Type = this.ddlLotType09.SelectedValue;
            lotTemplateInfo.LotAttr09Value = (this.ddlLotType09.SelectedValue == "OptionList") ? this.ddlLotValue09.SelectedValue : this.txtLotValue09.Text.Trim();
            if (int.TryParse(this.txtSeqNo10.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.LotAttr10Seqno = int.Parse(this.txtSeqNo10.Text.Trim());
            }
            else
            {
                lotTemplateInfo.LotAttr10Seqno = tempInt;
            }
            lotTemplateInfo.LotAttr10Label = this.txtLot10.Text.Trim();
            lotTemplateInfo.LotAttr10Visible = this.chkLotVisible10.Checked ? "Y" : "N";
            lotTemplateInfo.RfLotAttr10Visible = this.chkLotRFVisible10.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr10Mandatory = this.chkLotMandatory10.Checked ? "Y" : "N";
            lotTemplateInfo.LotAttr10Type = this.ddlLotType10.SelectedValue;
            lotTemplateInfo.LotAttr10Value = (this.ddlLotType10.SelectedValue == "OptionList") ? this.ddlLotValue10.SelectedValue : this.txtLotValue10.Text.Trim();
            if (int.TryParse(this.txtSeqNo11.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.ProduceDateSeqno = int.Parse(this.txtSeqNo11.Text.Trim());
            }
            else
            {
                lotTemplateInfo.ProduceDateSeqno = tempInt;
            }
            lotTemplateInfo.ProduceDateLabel = this.txtProduct.Text.Trim();
            lotTemplateInfo.ProduceDateVisible = this.chkLotVisible11.Checked ? "Y" : "N";
            lotTemplateInfo.RfProduceDateVisible = this.chkLotRFVisible11.Checked ? "Y" : "N";
            lotTemplateInfo.ProduceDateMandatory = this.chkLotMandatory11.Checked ? "Y" : "N";
            if (int.TryParse(this.txtSeqNo12.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.ExpiryDateSeqno = int.Parse(this.txtSeqNo12.Text.Trim());
            }
            else
            {
                lotTemplateInfo.ExpiryDateSeqno = tempInt;
            }
            lotTemplateInfo.ExpiryDateLabel = this.txtExpiryDate.Text.Trim();
            lotTemplateInfo.ExpiryDateVisible = this.chkLotVisible12.Checked ? "Y" : "N";
            lotTemplateInfo.RfExpiryDateVisible = this.chkLotRFVisible12.Checked ? "Y" : "N";
            lotTemplateInfo.ExpiryDateMandatory = this.chkLotMandatory12.Checked ? "Y" : "N";
            if (int.TryParse(this.txtSeqNo13.Text.Trim(), out tempInt))
            {
                lotTemplateInfo.ExternalLotSeqno = int.Parse(this.txtSeqNo13.Text.Trim());
            }
            else
            {
                lotTemplateInfo.ExternalLotSeqno = tempInt;
            }
            lotTemplateInfo.ExternalLotLabel = this.txtExternal.Text.Trim();
            lotTemplateInfo.ExternalLotVisible = this.chkLotVisible13.Checked ? "Y" : "N";
            lotTemplateInfo.RfExternalLotVisible = this.chkLotRFVisible13.Checked ? "Y" : "N";
            lotTemplateInfo.ExternalLotMandatory = this.chkLotMandatory13.Checked ? "Y" : "N";
            return lotTemplateInfo;
        }

        private void InitLotAttrTypeDDL(DropDownList ddl)
        {
            if (this.sysCodeLotAttrType == null)
            {
                this.sysCodeLotAttrType = CommoneMethodServiceClientProxy.GetInstance().GetSysCodeDataSource("LotAttrType");
            }
            ddl.DataSource = this.sysCodeLotAttrType;
            ddl.DataTextField = "SysCodeText";
            ddl.DataValueField = "SysCodeValue";
            ddl.DataBind();
        }

        private void InitLotAttrValueDDL(DropDownList ddl)
        {
            if (this.sysCodeLotAttrValue == null)
            {
                this.sysCodeLotAttrValue = CommoneMethodServiceClientProxy.GetInstance().GetLotAttributeCode4LotTemplate();
            }
            ddl.DataSource = this.sysCodeLotAttrValue;
            ddl.DataBind();
        }

        private void InitLotTemplateDropDownLit()
        {
            this.InitLotAttrTypeDDL(this.ddlLotType01);
            this.InitLotAttrTypeDDL(this.ddlLotType02);
            this.InitLotAttrTypeDDL(this.ddlLotType03);
            this.InitLotAttrTypeDDL(this.ddlLotType04);
            this.InitLotAttrTypeDDL(this.ddlLotType05);
            this.InitLotAttrTypeDDL(this.ddlLotType06);
            this.InitLotAttrTypeDDL(this.ddlLotType07);
            this.InitLotAttrTypeDDL(this.ddlLotType08);
            this.InitLotAttrTypeDDL(this.ddlLotType09);
            this.InitLotAttrTypeDDL(this.ddlLotType10);
            this.ddlLotType09.SelectedValue = "OptionList";
            this.InitLotAttrValueDDL(this.ddlLotValue01);
            this.InitLotAttrValueDDL(this.ddlLotValue02);
            this.InitLotAttrValueDDL(this.ddlLotValue03);
            this.InitLotAttrValueDDL(this.ddlLotValue04);
            this.InitLotAttrValueDDL(this.ddlLotValue05);
            this.InitLotAttrValueDDL(this.ddlLotValue06);
            this.InitLotAttrValueDDL(this.ddlLotValue07);
            this.InitLotAttrValueDDL(this.ddlLotValue08);
            this.InitLotAttrValueDDL(this.ddlLotValue09);
            this.InitLotAttrValueDDL(this.ddlLotValue10);
            this.ddlLotValue09.Text = "货品属性";
        }

        private void InsertLotTemplateInfo()
        {
            try
            {
                LotTemplateInfo lotTemplateInfo = new LotTemplateInfo();
                lotTemplateInfo = this.GetLotTemplateInfo4Form(lotTemplateInfo);
                lotTemplateInfo.CreatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Insert(lotTemplateInfo, "LOT_TEMPLATE") + base.GetGlobalMsgResource("C004");
                base.DataEntityViewState = lotTemplateInfo;
                this.txtLotTemplateID.Enabled = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        private void LoadData()
        {
            this.InitLotTemplateDropDownLit();
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.SetLotTemplateInfo2Form();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            this.chkLotVisible09.Checked = true;
            this.chkLotRFVisible09.Checked = true;
            this.chkLotMandatory09.Checked = true;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
                this.txtLot10.Text = "入库通知单号";
                this.txtLot09.Text = "货品属性";
            }
        }

        private void SetLotTemplateInfo2Form()
        {
            try
            {
                string lotTemplateID = base.Request.QueryString["ID"].ToString();
                LotTemplateInfo lotTemplate = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(lotTemplateID, "LOT_TEMPLATE") as LotTemplateInfo;
                base.DataEntityViewState = lotTemplate;
                if (lotTemplate != null)
                {
                    this.SetLotTemplateInfo2Form(lotTemplate);
                    this.txtLotTemplateID.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void SetLotTemplateInfo2Form(LotTemplateInfo lotTemplateInfo)
        {
            this.txtLotTemplateID.Text = lotTemplateInfo.LotTemplateID;
            this.txtDescription.Text = lotTemplateInfo.Description;
            this.chkSysCreated.Checked = lotTemplateInfo.SystemCreated == "Y";
            this.chkIsActive.Checked = lotTemplateInfo.IsActive == "Y";
            this.txtSeqNo1.Text = lotTemplateInfo.LotAttr01Seqno.ToString();
            this.txtLot01.Text = lotTemplateInfo.LotAttr01Label;
            this.chkLotVisible01.Checked = lotTemplateInfo.LotAttr01Visible == "Y";
            this.chkLotRFVisible01.Checked = lotTemplateInfo.RfLotAttr01Visible == "Y";
            this.chkLotMandatory01.Checked = lotTemplateInfo.LotAttr01Mandatory == "Y";
            this.ddlLotType01.SelectedValue = lotTemplateInfo.LotAttr01Type;
            if (this.ddlLotType01.SelectedValue == "OptionList")
            {
                this.ddlLotValue01.SelectedValue = lotTemplateInfo.LotAttr01Value;
                this.ddlLotValue01.Style.Add("display", "block");
                this.txtLotValue01.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue01.Text = lotTemplateInfo.LotAttr01Value;
            }
            this.txtSeqNo2.Text = lotTemplateInfo.LotAttr02Seqno.ToString();
            this.txtLot02.Text = lotTemplateInfo.LotAttr02Label;
            this.chkLotVisible02.Checked = lotTemplateInfo.LotAttr02Visible == "Y";
            this.chkLotRFVisible02.Checked = lotTemplateInfo.RfLotAttr02Visible == "Y";
            this.chkLotMandatory02.Checked = lotTemplateInfo.LotAttr02Mandatory == "Y";
            this.ddlLotType02.SelectedValue = lotTemplateInfo.LotAttr02Type;
            if (this.ddlLotType02.SelectedValue == "OptionList")
            {
                this.ddlLotValue02.SelectedValue = lotTemplateInfo.LotAttr02Value;
                this.ddlLotValue02.Style.Add("display", "block");
                this.txtLotValue02.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue02.Text = lotTemplateInfo.LotAttr02Value;
            }
            this.txtSeqNo3.Text = lotTemplateInfo.LotAttr03Seqno.ToString();
            this.txtLot03.Text = lotTemplateInfo.LotAttr03Label;
            this.chkLotVisible03.Checked = lotTemplateInfo.LotAttr03Visible == "Y";
            this.chkLotRFVisible03.Checked = lotTemplateInfo.RfLotAttr03Visible == "Y";
            this.chkLotMandatory03.Checked = lotTemplateInfo.LotAttr03Mandatory == "Y";
            this.ddlLotType03.SelectedValue = lotTemplateInfo.LotAttr03Type;
            if (this.ddlLotType03.SelectedValue == "OptionList")
            {
                this.ddlLotValue03.SelectedValue = lotTemplateInfo.LotAttr03Value;
                this.ddlLotValue03.Style.Add("display", "block");
                this.txtLotValue03.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue03.Text = lotTemplateInfo.LotAttr03Value;
            }
            this.txtSeqNo4.Text = lotTemplateInfo.LotAttr04Seqno.ToString();
            this.txtLot04.Text = lotTemplateInfo.LotAttr04Label;
            this.chkLotVisible04.Checked = lotTemplateInfo.LotAttr04Visible == "Y";
            this.chkLotRFVisible04.Checked = lotTemplateInfo.RfLotAttr04Visible == "Y";
            this.chkLotMandatory04.Checked = lotTemplateInfo.LotAttr04Mandatory == "Y";
            this.ddlLotType04.SelectedValue = lotTemplateInfo.LotAttr04Type;
            if (this.ddlLotType04.SelectedValue == "OptionList")
            {
                this.ddlLotValue04.SelectedValue = lotTemplateInfo.LotAttr04Value;
                this.ddlLotValue04.Style.Add("display", "block");
                this.txtLotValue04.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue04.Text = lotTemplateInfo.LotAttr04Value;
            }
            this.txtSeqNo5.Text = lotTemplateInfo.LotAttr05Seqno.ToString();
            this.txtLot05.Text = lotTemplateInfo.LotAttr05Label;
            this.chkLotVisible05.Checked = lotTemplateInfo.LotAttr05Visible == "Y";
            this.chkLotRFVisible05.Checked = lotTemplateInfo.RfLotAttr05Visible == "Y";
            this.chkLotMandatory05.Checked = lotTemplateInfo.LotAttr05Mandatory == "Y";
            this.ddlLotType05.SelectedValue = lotTemplateInfo.LotAttr05Type;
            if (this.ddlLotType05.SelectedValue == "OptionList")
            {
                this.ddlLotValue05.SelectedValue = lotTemplateInfo.LotAttr05Value;
                this.ddlLotValue05.Style.Add("display", "block");
                this.txtLotValue05.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue05.Text = lotTemplateInfo.LotAttr05Value;
            }
            this.txtSeqNo6.Text = lotTemplateInfo.LotAttr06Seqno.ToString();
            this.txtLot06.Text = lotTemplateInfo.LotAttr06Label;
            this.chkLotVisible06.Checked = lotTemplateInfo.LotAttr06Visible == "Y";
            this.chkLotRFVisible06.Checked = lotTemplateInfo.RfLotAttr06Visible == "Y";
            this.chkLotMandatory06.Checked = lotTemplateInfo.LotAttr06Mandatory == "Y";
            this.ddlLotType06.SelectedValue = lotTemplateInfo.LotAttr06Type;
            if (this.ddlLotType06.SelectedValue == "OptionList")
            {
                this.ddlLotValue06.SelectedValue = lotTemplateInfo.LotAttr06Value;
                this.ddlLotValue06.Style.Add("display", "block");
                this.txtLotValue06.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue06.Text = lotTemplateInfo.LotAttr06Value;
            }
            this.txtSeqNo7.Text = lotTemplateInfo.LotAttr07Seqno.ToString();
            this.txtLot07.Text = lotTemplateInfo.LotAttr07Label;
            this.chkLotVisible07.Checked = lotTemplateInfo.LotAttr07Visible == "Y";
            this.chkLotRFVisible07.Checked = lotTemplateInfo.RfLotAttr07Visible == "Y";
            this.chkLotMandatory07.Checked = lotTemplateInfo.LotAttr07Mandatory == "Y";
            this.ddlLotType07.SelectedValue = lotTemplateInfo.LotAttr07Type;
            if (this.ddlLotType07.SelectedValue == "OptionList")
            {
                this.ddlLotValue07.SelectedValue = lotTemplateInfo.LotAttr07Value;
                this.ddlLotValue07.Style.Add("display", "block");
                this.txtLotValue07.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue07.Text = lotTemplateInfo.LotAttr07Value;
            }
            this.txtSeqNo8.Text = lotTemplateInfo.LotAttr08Seqno.ToString();
            this.txtLot08.Text = lotTemplateInfo.LotAttr08Label;
            this.chkLotVisible08.Checked = lotTemplateInfo.LotAttr08Visible == "Y";
            this.chkLotRFVisible08.Checked = lotTemplateInfo.RfLotAttr08Visible == "Y";
            this.chkLotMandatory08.Checked = lotTemplateInfo.LotAttr08Mandatory == "Y";
            this.ddlLotType08.SelectedValue = lotTemplateInfo.LotAttr08Type;
            if (this.ddlLotType08.SelectedValue == "OptionList")
            {
                this.ddlLotValue08.SelectedValue = lotTemplateInfo.LotAttr08Value;
                this.ddlLotValue08.Style.Add("display", "block");
                this.txtLotValue08.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue08.Text = lotTemplateInfo.LotAttr08Value;
            }
            this.txtSeqNo9.Text = lotTemplateInfo.LotAttr09Seqno.ToString();
            this.txtLot09.Text = lotTemplateInfo.LotAttr09Label;
            this.chkLotVisible09.Checked = lotTemplateInfo.LotAttr09Visible == "Y";
            this.chkLotRFVisible09.Checked = lotTemplateInfo.RfLotAttr09Visible == "Y";
            this.chkLotMandatory09.Checked = lotTemplateInfo.LotAttr09Mandatory == "Y";
            this.ddlLotType09.SelectedValue = lotTemplateInfo.LotAttr09Type;
            if (this.ddlLotType09.SelectedValue == "OptionList")
            {
                this.ddlLotValue09.SelectedValue = lotTemplateInfo.LotAttr09Value;
                this.ddlLotValue09.Style.Add("display", "block");
                this.txtLotValue09.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue09.Text = lotTemplateInfo.LotAttr09Value;
            }
            this.txtSeqNo10.Text = lotTemplateInfo.LotAttr10Seqno.ToString();
            this.txtLot10.Text = lotTemplateInfo.LotAttr10Label;
            this.chkLotVisible10.Checked = lotTemplateInfo.LotAttr10Visible == "Y";
            this.chkLotRFVisible10.Checked = lotTemplateInfo.RfLotAttr10Visible == "Y";
            this.chkLotMandatory10.Checked = lotTemplateInfo.LotAttr10Mandatory == "Y";
            this.ddlLotType10.SelectedValue = lotTemplateInfo.LotAttr10Type;
            if (this.ddlLotType10.SelectedValue == "OptionList")
            {
                this.ddlLotValue10.SelectedValue = lotTemplateInfo.LotAttr10Value;
                this.ddlLotValue10.Style.Add("display", "block");
                this.txtLotValue10.Style.Add("display", "none");
            }
            else
            {
                this.txtLotValue10.Text = lotTemplateInfo.LotAttr10Value;
            }
            this.txtSeqNo11.Text = lotTemplateInfo.ProduceDateSeqno.ToString();
            this.txtProduct.Text = string.IsNullOrEmpty(lotTemplateInfo.ProduceDateLabel.ToString()) ? "" : lotTemplateInfo.ProduceDateLabel.ToString();
            this.chkLotVisible11.Checked = lotTemplateInfo.ProduceDateVisible == "Y";
            this.chkLotRFVisible11.Checked = lotTemplateInfo.RfProduceDateVisible == "Y";
            this.chkLotMandatory11.Checked = lotTemplateInfo.ProduceDateMandatory == "Y";
            this.txtSeqNo12.Text = lotTemplateInfo.ExpiryDateSeqno.ToString();
            this.txtExpiryDate.Text = string.IsNullOrEmpty(lotTemplateInfo.ExpiryDateLabel.ToString()) ? "" : lotTemplateInfo.ExpiryDateLabel.ToString();
            this.chkLotVisible12.Checked = lotTemplateInfo.ExpiryDateVisible == "Y";
            this.chkLotRFVisible12.Checked = lotTemplateInfo.RfExpiryDateVisible == "Y";
            this.chkLotMandatory12.Checked = lotTemplateInfo.ExpiryDateMandatory == "Y";
            this.txtSeqNo13.Text = lotTemplateInfo.ExternalLotSeqno.ToString();
            this.txtExternal.Text = string.IsNullOrEmpty(lotTemplateInfo.ExternalLotLabel.ToString()) ? "" : lotTemplateInfo.ExternalLotLabel.ToString();
            this.chkLotVisible13.Checked = lotTemplateInfo.ExternalLotVisible == "Y";
            this.chkLotRFVisible13.Checked = lotTemplateInfo.RfExternalLotVisible == "Y";
            this.chkLotMandatory13.Checked = lotTemplateInfo.ExternalLotMandatory == "Y";
        }

        private void UpdateLotTemplateInfo()
        {
            try
            {
                LotTemplateInfo lotTemplateInfo = base.DataEntityViewState as LotTemplateInfo;
                lotTemplateInfo = this.GetLotTemplateInfo4Form(lotTemplateInfo);
                lotTemplateInfo.UpdatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(lotTemplateInfo, "LOT_TEMPLATE") + base.GetGlobalMsgResource("C002");
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

